package com.ruoyi.web.controller.app;

import com.ruoyi.order.domain.app.Vo.DeliveryModeVo;
import com.ruoyi.order.domain.app.Vo.ProductViewDetail;
import com.ruoyi.order.domain.app.Vo.SkuVo;
import com.ruoyi.order.domain.app.Vo.*;
import com.ruoyi.order.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 陈焕然
 * @version 1.0
 */
@Controller
@RequestMapping("/app")

public class ProductAppController {
    @Autowired
    private IProductService productService;

    /**
     * *  current: this.current,
*      *         prodName: this.prodName,
*      *         size: this.size,
*      *         sort: this.sts,
*      *         orderBy: this.orderBy,
*      *         isAllProdType: !0
     * @param
     * @param current
     * @param size
     * @return
     * GET /search/searchProdPage?current=1&prodName=%E8%99%8E%E5%B9%B4&
     * size=10&sort=0&orderBy=1&isAllProdType=true HTTP/1.1
     */
    @RequestMapping("/search/searchProdPage")
    @ResponseBody
    public ProductViewResultVo getSearchProdPage(Integer categoryId, Integer current, Integer size){
        ProductViewResultVo productViewResultVo = new ProductViewResultVo();
        List<ProductViewDetail> list = productService.getsearchProdPage(categoryId);
        if(list!=null&&list.size()>0){
            productViewResultVo.setPages(1);
            productViewResultVo.setCurrent(current);
            productViewResultVo.setSize(size);
            productViewResultVo.setTotal(list.size());
            productViewResultVo.setRecords(list);
        }
        return productViewResultVo;
    }
///search/searchProdPage?categoryId=148&current=1&size=10&sort=0&isAllProdType=true
    /**
     * 根据商品id获取商品详情
     * @param prodId
     * @return
     */
    @RequestMapping("/prod/prodInfo")
    @ResponseBody
    public ProdInfoResultVo getProdInfo(Integer prodId ){
        List<SkuVo> skuVos = productService.getSku(prodId);
        ProdInfoResultVo result = new ProdInfoResultVo();
        if(skuVos !=null && skuVos.size()>0){
            result = productService.getProdInfo(prodId);
            result.setSkuList(skuVos);
        }
        DeliveryModeVo deliveryModeVo = new DeliveryModeVo();
        result.setDeliveryModeVO(deliveryModeVo);
        result.setSkuList(skuVos);
        return result;
    }

    @RequestMapping("/prod/prodCommPageByProd")
    @ResponseBody
    public String  getprodCommPageByProd(String prodId ){
        return "{\"total\":0,\"current\":1,\"pages\":0,\"size\":10,\"optimizeCountSql\":true,\"records\":[],\"maxLimit\":null,\"searchCount\":true,\"orders\":[],\"countId\":null}";
    }

    @RequestMapping("/prod/prodCommData")
    @ResponseBody
    public ProdViewVo getprodCommData(String prodId ){
        ProdViewVo prodViewVo = new ProdViewVo();
        return prodViewVo;
    }

    @RequestMapping("/prod/tag/prodTagList")
    @ResponseBody
    public List<ProdTag>  getprodTagList(){
        ProdTag prodTag = new ProdTag();
        prodTag.setId(1);
        prodTag.setSeq("2");
        prodTag.setStyle("2");
        prodTag.setTitle("今年热门");
        List<ProdTag> list = new ArrayList<>();
        list.add(prodTag);
        return list;
    }

    @RequestMapping("/prod/prodList")
    @ResponseBody
    public ProductResultVo  getProdListByTagId(Integer tagId,Integer size ){
        ProductResultVo productResultVo = new ProductResultVo();
        return productResultVo;
    }
    @RequestMapping("coupon/listByProdId")
    @ResponseBody
    public String  listByProdId(){
        return "[{\"cashCondition\":100.0,\"couponName\":\"血亏券\",\"reduceAmount\":0.0,\"shopName\":null,\"pic\":null,\"prodId\":null,\"couponId\":74,\"suitableProdType\":0,\"stocks\":8732,\"validTimeType\":1,\"userHasCount\":null,\"subTitle\":\"1\",\"couponType\":2,\"price\":null,\"startTime\":\"2021-01-08\",\"shopId\":1,\"afterReceiveDays\":0,\"limitNum\":100,\"putonStatus\":1,\"prods\":null,\"shopLogo\":null,\"sourceStock\":9613,\"receiveTime\":null,\"couponDiscount\":9.9,\"couponUserId\":null,\"curUserReceiveCount\":null,\"endTime\":\"2022-03-31\",\"validDays\":1,\"status\":null,\"overdueStatus\":1},{\"cashCondition\":50.0,\"couponName\":\"邀请函\",\"reduceAmount\":5.0,\"shopName\":null,\"pic\":null,\"prodId\":null,\"couponId\":215,\"suitableProdType\":0,\"stocks\":10957,\"validTimeType\":2,\"userHasCount\":null,\"subTitle\":\"42\",\"couponType\":1,\"price\":null,\"startTime\":null,\"shopId\":1,\"afterReceiveDays\":0,\"limitNum\":11,\"putonStatus\":1,\"prods\":null,\"shopLogo\":null,\"sourceStock\":11111,\"receiveTime\":null,\"couponDiscount\":0.0,\"couponUserId\":null,\"curUserReceiveCount\":null,\"endTime\":null,\"validDays\":1,\"status\":null,\"overdueStatus\":1}]\n";
    }
}
